package com.bootdo.system.service.impl;

import com.bootdo.system.dao.CategoryDao;
import com.bootdo.system.domain.CategoryDO;
import com.bootdo.system.domain.ProjectDO;
import com.sun.tools.internal.xjc.model.CAdapter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.bootdo.system.dao.ProductDao;
import com.bootdo.system.domain.ProductDO;
import com.bootdo.system.service.ProductService;


@Service
public class ProductServiceImpl implements ProductService {
	@Autowired
	private ProductDao productDao;
	@Autowired
	private CategoryDao categoryDao;

	@Override
	public ProductDO get(Integer productId){
		ProductDO productDO = productDao.get(productId);
		if(productDO==null){
			return null;
		}
		if(productDO.getCategoryId()!=null){
			CategoryDO categoryDO = categoryDao.get(productDO.getCategoryId());
			productDO.setCategoryDO(categoryDO);
		}

		return productDO;
	}

	@Override
	public List<ProductDO> list(Map<String, Object> map){

		map.put("sort","product_id");
		List<ProductDO> list = productDao.list(map);

		/*for (ProductDO productDO : list) {
			CategoryDO categoryDO = categoryDao.get(productDO.getCategoryId());
			productDO.setCategoryDO(categoryDO);
		}*/
		return list;
	}

	@Override
	public int count(Map<String, Object> map){
		return productDao.count(map);
	}

	@Override
	public int save(ProductDO product){
		java.sql.Date date = new java.sql.Date(new Date().getTime());
		product.setCreateTime(date);
		return productDao.save(product);
	}

	@Override
	public int update(ProductDO product){
		return productDao.update(product);
	}

	@Override
	public int remove(Integer productId){
		return productDao.remove(productId);
	}

	@Override
	public int batchRemove(Integer[] productIds){
		return productDao.batchRemove(productIds);
	}

	@Override
	public List<ProductDO> listall() {
		return productDao.listall();
	}

	@Override
	public List<ProductDO> listallDistinct() {
		return productDao.listallDistinct();
	}

	@Override
	public List<ProductDO> getAggRestlt(ProductDO projectDO) {
		return productDao.getAggRestlt(projectDO);
	}


}

